package com.example.demo.encrypt;

//import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
//import org.apache.ibatis.type.JdbcType;
//import org.apache.ibatis.type.MappedJdbcTypes;
//import org.apache.ibatis.type.MappedTypes;
import org.springframework.util.StringUtils;

/**
 * @program: mpf-mod-openapi-service
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-07-08 09:17
 **/
//@MappedTypes({String.class})
//@MappedJdbcTypes({JdbcType.VARCHAR})
public class EncryptTypeHandler{ //extends AbstractJsonTypeHandler<String> {

    public static String key;

//    @Override
    protected String parse(String obj) {
        if(StringUtils.isEmpty(obj)){
            return obj;
        }
        String decrypt = AESUtil.decrypt(obj, key);
        return StringUtils.isEmpty(decrypt)?obj:decrypt;
    }

//    @Override
    protected String toJson(String obj) {
        if(StringUtils.isEmpty(obj)){
            return obj;
        }
        String encrypt = AESUtil.encrypt(obj, key);
        return StringUtils.isEmpty(encrypt)?obj:encrypt;
    }

}
